<?php
namespace Admin\Model;
use Think\Model;

class RefundModel extends Model{
    protected $connection = 'DB_CONFIG2';

	/**
	 * 退款订单统计
	 * 根据条件，返回订单总数
	 * @param unknown $where
	 */
	public function getRefundCount($where=null){
		$orderNum = $this->alias('r')
            ->join(C('DB_PREFIX').'order as o ON o.ordersn = r.ordersn')
			->where($where)->select();
		if ($orderNum) {
			return count($orderNum);
		}else{
			return null;
		}
	}

	/**
	 * 退款列表
	 * @param unknown $where
	 */
	public function getRefundList($page,$where=null,$p=null,$type="select"){
		if($type=="select"){
			$orderList = $this->alias('as r')->
            join(C('DB_PREFIX').'order as o ON o.ordersn = r.ordersn')->
            join(C('DB_PREFIX').'order_info as oi ON o.ordersn = oi.ordersn')->
            join(C('DB_PREFIX').'user as u ON oi.openid = u.openid')->
            join(C('DB_PREFIX').'user_car as uc ON oi.user_car_id = uc.id')->
            where($where)->order('r.id desc')->page($p)->select();
        }
	    else if($type=="find"){
	    	$orderList = $this->alias('as r')->
            join(C('DB_PREFIX').'order as o ON o.ordersn = r.ordersn')->
            join(C('DB_PREFIX').'order_info as oi ON o.ordersn = oi.ordersn')->
            join(C('DB_PREFIX').'user as u ON oi.openid = u.openid')->
            join(C('DB_PREFIX').'user_car as uc ON oi.user_car_id = uc.id')->
            where($where)->order('r.id desc')->find();
	    }
	    //判断是否有数据
		if ($orderList) {
			return $orderList;
		}else{
			return null;
		}
	}

}
